package com.dong.zk;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.proto.WatcherEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * @author: dzj
 * @date 2018/10/10-9:11
 */
public class ZkConnector implements Watcher {
    public static final String zkServerPath = "10.0.109.142:2181";
    public static final Integer timeout=5000;
    public static Logger logger = LoggerFactory.getLogger(ZkConnector.class);


    public static void main(String[] args) throws IOException, InterruptedException {


        ZooKeeper zk = new ZooKeeper(zkServerPath,timeout,new ZkConnector());
        if(logger.isDebugEnabled()) {
            logger.debug("客户端开始连接zookeeper服务器....");
       //     System.out.println("客户端开始连接zookeeper服务器....");


            logger.debug("连接状态: {}",zk.getState());
            //     System.out.println("连接状态:"+zk.getState());
            new Thread().sleep(3000);
            Thread.sleep(2000);
            //   System.out.println("连接状态:"+zk.getState());
               logger.debug("连接状态: {}",zk.getState());

        }
    }

    public void process(WatchedEvent watchedEvent) {
        System.out.println("接受到事件通知: "+watchedEvent);

    }
}
